<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='System Settings',active='setting'">
<header th:replace="admin/fragments/header::headerFragment(${title},${active})"></header>
<link th:href="@{/admin/plugins/toggles/toggles.css}" rel="stylesheet" />

<body class="fixed-left">
    <div id="wrapper">
        <div th:replace="admin/fragments/header::header-body"></div>
        <div class="content-page">
            <div class="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12">
                            <h4 class="page-title">System Settings</h4>
                        </div>
                        <div class="col-md-6">
                            <div class="panel panel-color panel-primary">
                                <div class="panel-heading">
                                    <h3 class="panel-title">Global</h3>
                                </div>
                                <div class="panel-body">
                                    <form class="form-horizontal" role="form" id="global-form">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Site Name</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="site_title"
                                                    placeholder="Site Name" th:value="${options.site_title}"
                                                    required="required" aria-required="true" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Description</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="site_description"
                                                    placeholder="Description" th:value="${options.site_description}"
                                                    required="required" aria-required="true" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">ICP Number</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="site_record"
                                                    placeholder="ICP Number" th:value="${options.site_record}"
                                                    required="required" aria-required="true" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Google Verification</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="google_site_verification"
                                                    placeholder="Google Verification"
                                                    th:value="${options.google_site_verification}" required="required"
                                                    aria-required="true" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Baidu Verification</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="baidu_site_verification"
                                                    placeholder="Baidu Verification"
                                                    th:value="${options.baidu_site_verification}" required="required"
                                                    aria-required="true" />
                                            </div>
                                        </div>

                                        <input type="hidden" name="allow_install" id="allow_install" />
                                        <div class="clearfix pull-right">
                                            <button type="button" class="btn btn-primary waves-effect waves-light"
                                                onclick="saveSetting()">
                                                Save Settings
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="panel panel-color panel-inverse">
                                <div class="panel-heading">
                                    <h3 class="panel-title">Personalized Settings</h3>
                                </div>
                                <div class="panel-body">
                                    <form id="indivi-form" class="form-horizontal" role="form">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">CSDN Blog</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_csdn"
                                                    th:value="${options.social_csdn}" placeholder="CSDN" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Resume</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_resume"
                                                    th:value="${options.social_resume}" placeholder="Resume" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Jianshu</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_jianshu"
                                                    th:value="${options.social_jianshu}" placeholder="Jianshu" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Weibo</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_weibo"
                                                    th:value="${options.social_weibo}" placeholder="Weibo" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Zhihu</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_zhihu"
                                                    th:value="${options.social_zhihu}" placeholder="Zhihu" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Github</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_github"
                                                    th:value="${options.social_github}" placeholder="Github" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Twitter</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" name="social_twitter"
                                                    th:value="${options.social_twitter}" placeholder="Twitter" />
                                            </div>
                                        </div>
                                        <div class="clearfix pull-right">
                                            <button type="button" class="btn btn-inverse waves-effect waves-light"
                                                onclick="saveIndiviSetting()">
                                                Save Settings
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>

                    </div>
                    <div th:replace="admin/fragments/footer :: footer-content"></div>
                </div>
            </div>
        </div>
    </div>
    <div th:replace="admin/fragments/footer :: footer"></div>
    <script src="//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js"></script>
    <script type="text/javascript">
        /*<![CDATA[*/
        var tale = new $.tale();

        function saveSetting() {
            var param = $('#global-form').serialize();
            tale.post({
                url: '/admin/setting',
                data: param,
                success: function (result) {
                    if (result && result.code == 'success') {
                        tale.alertOk('Saved Successfully!');
                    } else {
                        tale.alertError(result.msg || 'Save Failed!');
                    }
                }
            });
        }

        function saveIndiviSetting() {
            var param = $('#indivi-form').serialize();
            tale.post({
                url: '/admin/setting',
                data: param,
                success: function (result) {
                    if (result && result.code == 'success') {
                        tale.alertOk('Saved Successfully!');
                    } else {
                        tale.alertError(result.msg || 'Save Failed!');
                    }
                }
            });
        }

        function allow_reinstall(obj) {
            var this_ = $(obj);
            var on = this_.find('.toggle-on.active').length;
            var off = this_.find('.toggle-off.active').length;
            if (on == 1) {
                $('#allow_install').val(0);
            }
            if (off == 1) {
                $('#allow_install').val(1);
            }
        }

        function backup(type) {
            var param = {
                bk_type: type,
                bk_path: $('#backup_dir').val()
            };
            tale.post({
                url: '/admin/setting/backup',
                data: param,
                success: function (result) {
                    if (result && result.code == 'success') {
                        if (result.payload && result.payload.attach_path) {
                            swal('Backup Successful!', 'Your attachment at <mark>' + result.payload.attach_path + '</mark><br/><br/>' +
                                'themes at <mark>' + result.payload.theme_path + '</mark>', 'success');
                            $('#backup_dir').val('');
                        }
                        if (result.payload.sql_path) {
                            window.location.href = '/upload/' + result.payload.sql_path;
                        }
                    } else {
                        tale.alertError(result.msg || 'Backup Failed!');
                    }
                }
            });
        }

        $('.allow-1').toggles({
            on: true,
            text: {
                on: 'ON',
                off: 'OFF'
            }
        });
        $('.allow-0').toggles({
            off: true,
            text: {
                on: 'ON',
                off: 'OFF'
            }
        });
    /*]]>*/
    </script>
</body>

</html>